package kr.snake75.web;

import javax.inject.Inject;

import kr.snake75.web.member.MemberList;
import kr.snake75.web.member.MemberServiceImpl;
import kr.snake75.web.member.MemberVO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("member")
public class MemberController {
	
	private static final Logger logger = LoggerFactory.getLogger(MemberController.class);

	@Inject
	private MemberServiceImpl svc;

	@RequestMapping(value="/select.json", 
			method = RequestMethod.GET ,
			headers="Accept=application/json",
			produces = {MediaType.APPLICATION_JSON_VALUE})
	public @ResponseBody MemberVO selectJSON(String id) throws Exception {
		logger.info("id ====> " + id);
		return svc.select(id);
	}

	@RequestMapping(value="/select.xml", 
			method = RequestMethod.GET ,
			headers="Accept=http/xml",
			produces = {MediaType.APPLICATION_XML_VALUE})
	public @ResponseBody MemberVO selectXML(String id) throws Exception {
		
		return svc.select(id);
	}

	@RequestMapping(value="/selectAll.json", 
			method = RequestMethod.GET ,
			headers="Accept=application/json",
			produces = {MediaType.APPLICATION_JSON_VALUE})
	public @ResponseBody MemberList selectAllJSON(String id) throws Exception {
		
		MemberList list = new MemberList();
		list.setList(svc.selectAll());
		
		return list;
	}

	@RequestMapping(value="/selectAll.xml", 
			method = RequestMethod.GET ,
			headers="Accept=http/xml",
			produces = {MediaType.APPLICATION_XML_VALUE})
	public @ResponseBody MemberList selectAllXML(String id) throws Exception {
		
		MemberList list = new MemberList();
		list.setList(svc.selectAll());
		
		return list;
	}

}
